package com.chanjiedata.changbs.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chanjiedata.changbs.R;
import com.ruffian.library.widget.RTextView;


/**
 * 创建者     gao hua
 * 创建时间   9/5 0005 15:51
 * 描述	      ${TODO}
 * <p>
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */

public class MineItemLayout extends RelativeLayout {

    private boolean hasNext;
    private boolean hasRightText;
    private boolean hasBottomLine;
    private boolean hasLeftIcon;
    private String left_text,right_text;
    private int left_background;

    private View view;
    private TextView tvLeft;
    private RTextView tvRight;
    private ImageView ivNext;
    private ImageView ivLeft;
    private View line;

    public MineItemLayout(Context context) {
        this(context,null);
    }

    public MineItemLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs);
    }

    private void init(Context context , AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MineItemLayout);
        hasNext = a.getBoolean(R.styleable.MineItemLayout_has_mine_next, true);
        hasRightText = a.getBoolean(R.styleable.MineItemLayout_has_mine_right_text, true);
        hasBottomLine = a.getBoolean(R.styleable.MineItemLayout_has_bottom_line, true);
        hasLeftIcon = a.getBoolean(R.styleable.MineItemLayout_has_mine_left_icon, true);
        left_text = a.getString(R.styleable.MineItemLayout_left_mine_text);
        right_text = a.getString(R.styleable.MineItemLayout_right_mine_text);

        if (hasLeftIcon)
        {
            view = View.inflate(context, R.layout.mine_item_layout, this);
        }
        else
        {
            view = View.inflate(context, R.layout.mine_item_on_left_icon_layout, this);
        }
        tvLeft = view.findViewById(R.id.item_mine_left_tv);
        tvRight = view.findViewById(R.id.item_mine_right_tv);
        ivNext = view.findViewById(R.id.item_mine_next_iv);
        ivLeft = view.findViewById(R.id.item_mine_left_iv);
        line = view.findViewById(R.id.item_line);



        tvLeft.setText(left_text);

        left_background = a.getResourceId(R.styleable.MineItemLayout_left_mine_background, Color.BLACK);
        ivNext.setVisibility(hasNext ? View.VISIBLE :View.GONE);
        line.setVisibility(hasBottomLine ? View.VISIBLE:View.GONE);


        if (hasLeftIcon)
        {
            ivLeft.setImageResource(left_background);
        }else
        {
            ivLeft.setVisibility(View.GONE);
        }
        if(hasRightText) {
            tvRight.setVisibility(View.VISIBLE);
            tvRight.setText(right_text);
        }else {
            tvRight.setVisibility(View.GONE);
        }

    }

    public void setRightTextColor(int color) {
        tvRight.setTextColor(color);
    }
    public void setRightText(String rightText) {
        tvRight.setText(rightText);
    }
    public String getRightText() {
        return  tvRight.getText().toString().trim() ;
    }
}
